package com.yr.contrller;

import com.yr.service.FileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

/**
 * Created by gx on 2017/6/9.
 */
@RestController
@RequestMapping("/api/")
public class FileContrller {
    private static final Logger log = LoggerFactory.getLogger(FileContrller.class);
    @Autowired
    FileService fileService;

    @RequestMapping(value = "test")
    public String test(){
        return "ok";
    }

    @PostMapping("file")
    public String upload ( MultipartHttpServletRequest multipartRequest){

        try {
            fileService.upload(multipartRequest);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return "error";
        }
        return "success";

    }
}
